/*
 * Copyright 2016 Stuart Kent
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package com.example.mybugshaker.flow.email.screenshot;

import com.example.mybugshaker.utils.Logger;
import io.reactivex.Observable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import ohos.aafwk.ability.Ability;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import ohos.utils.net.Uri;
import org.jetbrains.annotations.NotNull;

public abstract class BaseScreenshotProvider implements ScreenshotProvider{
    @NotNull
    private final Context applicationContext;

    @NotNull
    private final Logger logger;

    public BaseScreenshotProvider(
            @NotNull final Context context,
            @NotNull final Logger flogger) {

        this.applicationContext = context;
        this.logger = flogger;
    }

    @NotNull
    public abstract Observable<PixelMap> getScreenshotPixelMap(@NotNull Ability ability);

    @NotNull
    @Override
    public final Observable<Uri> getScreenshotUri(@NotNull final Ability ability) {
        return getScreenshotPixelMap(ability)
                .observeOn(Schedulers.io())
                .flatMap((Function<PixelMap, Observable<Uri>>) pixelmap ->
                        ScreenshotUriObservable.create(applicationContext, pixelmap, logger));
    }

    protected final Observable<PixelMap> getNonMapViewsBitmap(@NotNull final Ability ability) {
        return PixelMapScreenShot.create(ability);
    }
}
